package com.hskn.hss.app.unread.controller;

import com.hskn.hss.app.unread.dto.NewsCountDto;
import com.hskn.hss.app.unread.dto.NoHandleCountDto;
import com.hskn.hss.app.unread.service.IUnreadService;
import com.hskn.hss.app.unread.to.NewsCountTo;
import com.hskn.hss.app.unread.to.NoHandleCountTo;
import com.hskn.hss.core.domain.BaseEntity;
import com.hskn.hss.core.utils.LoginUtils;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.module.user.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hskn
 * @since 2020-11-16
 */
@Slf4j
@RestController
@RequestMapping("/hss/app/unread")
public class APPUnreadController {
    @Autowired
    IUnreadService unreadService;

    /**
     * 未读数量
     */
    @PostMapping("/newsCount")
    public AjaxResult newsCount(@RequestBody NewsCountTo newsCountTo) {
        BaseEntity entity = new BaseEntity();
        User user = LoginUtils.getUser();
        newsCountTo.setPersonId(user.getUid());
        return AjaxResult.success(unreadService.getNewsCount(entity, new NewsCountDto(newsCountTo)));
    }

    /**
     * 报警违规未处理数量
     */
    @PostMapping("/getNoHandleCount")
    public AjaxResult getNoHandleCount(@RequestBody NoHandleCountTo noHandleCountTo) {
        User user = LoginUtils.getUser();
        noHandleCountTo.setPersonId(user.getUid());
        return AjaxResult.success(unreadService.getNoHandleCount(new NoHandleCountDto(noHandleCountTo)));
    }

}

